package demo;

import java.util.Random;

public class AuthCode {
    public static final String CHAR_CODE =  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    public static void main(String[] args) {
        System.out.println(getAuthCode(4));
    }
    public static String getAuthCode(int length){
        if(length<=0){return "code cannot be negative";};
        StringBuilder code = new StringBuilder(length);
        Random  random = new Random();
        for(int i = 0; i < length; i++){
            int index = random.nextInt( CHAR_CODE.length() );
            code.append( CHAR_CODE.charAt(index));
        }
        return code.toString();
    }
}
